package wps.util {
import flash.geom.Matrix;
import flash.geom.Point;

import mx.core.UIComponent;

public class GeomUtil {

    /**
     * 原地旋转，旋转后目标的坐标不变，rotation属性等于angle
     *
     * @param target 需要旋转的对象
     * @param angle 顺时针旋转的角度
     */
    public static function rotate(target:UIComponent, angle:Number):void {
        var m:Matrix = target.transform.matrix;

        var centerPoint:Point = new Point(target.width / 2, target.height / 2);
        var transformPoint:Point = m.transformPoint(centerPoint);

        m.translate(-transformPoint.x, -transformPoint.y);
        m.rotate(angle * Math.PI / 180);
        m.translate(transformPoint.x, transformPoint.y);

        target.transform.matrix = m;
    }

}

}
